<template>
  <div class="calendar-header">
    <div class="date-select">
      <select v-model="selectedYear">
        <option v-for="year in years" :key="year" :value="year">{{year}}年</option>
      </select>
      <span @click="lastMonth"><</span>
      <select v-model="selectedMonth">
        <option v-for="month in months" :key="month" :value="month">{{month}}月</option>
      </select>
      <span @click="nextMonth">></span>
    </div>
    <div class="today">
      <button @click="gotoToday">今天</button>
    </div>
  </div>
</template>

<script setup>
import {ref,onMounted} from 'vue'
import { createYears,createMonths } from '@/function';
import { storeToRefs } from 'pinia';
import { useCalendarStore } from '@/stores/calendar';

const {selectedYear,selectedMonth}=storeToRefs(useCalendarStore())
const {lastMonth,nextMonth,gotoToday}=useCalendarStore()

const years=ref([])
const months=ref([])


onMounted(()=>{
    years.value=createYears()
    months.value=createMonths()
})


</script>

<style scoped>
.calendar-header {
  display: flex;
  height: 50px;
  align-items: center;
  justify-content: space-around;

  background-image: linear-gradient(
    180deg,
    rgb(51, 186, 255, 0.1) 0%, rgb(51, 186, 255, 0) 100%
  );
  
  border-radius: 16px 16px 0 0;
}
.date-select{
    display: flex;
    color:#333;
    gap: 10px;
}
.date-select select{
    padding: 4px 10px;
    border: 1px solid #eee;
    border-radius: 6px;
}
.date-select select:hover{
    cursor: pointer;
    border: 1px solid #ccc;
}
.date-select span{
    color: #ccc;
    cursor: pointer;
}
.today button{
    padding: 4px 15px;
    border: 1px solid #eee;
    border-radius: 6px;
    background-color: #fff;
}
.today button:hover{
    cursor: pointer;
    border: 1px solid #ccc;
}

</style>
